package com.saifan.wyy_ov.common;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings;
import java.util.Map;
import lomasky.ma.httpUtils.HttpUtil;
import lomasky.ma.httpUtils.ICallBack;
import lomasky.ma.httpUtils.ResponseBean;



/**
 * @author Eicky
 * @Description: Activity基类
 * @date: 2016/4/23 13:19
 * @version: V1.0
 */
public abstract class NetActivity extends BaseActivity implements ICallBack {


    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();

    }

    public void post(String api ,Map<String, Object> params) {
        if (isNetWorkConnected(this)) {
            HttpUtil.post(this, api,params,this);
        } else {
//            ToastUtil.showToast(this, "请为您的设备设置网络");
            startActivity(new Intent(Settings.ACTION_SETTINGS));
        }

    }

    public void post(String api,Map<String, Object> params, String tip) {

        if (isNetWorkConnected(this)) {
            HttpUtil.post(this, api,params,tip,this);
        } else {
//            ToastUtil.showToast(this, "请为您的设备设置网络");
            startActivity(new Intent(Settings.ACTION_SETTINGS));
        }

    }


    /**
     * 检测网络是否可用
     *
     * @param context
     * @return
     */
    public boolean isNetWorkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }

        return false;
    }

    @Override
    public abstract void err(String e)  ;

    @Override
    public abstract void ok(ResponseBean response);
}
